<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            margin: 200px;
        }
        span{
            background-color: #333;
            width: 40px;
            height: 40px;
            font-size: 20px;
            color: #fff;
            display: inline-block;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>
<body>
    <div>
        <span class="hour">1</span>
        <span class="minuite">2</span>
        <span class="second">3</span>
    </div>
    <script>
        var hour = document.querySelector('.hour');
        var minuite = document.querySelector('.minuite');
        var second = document.querySelector('.second');
       
        var inputTime = +new Date('2020-10-1 00:00:00');
        countDown();//先调用一次函数，防止第一次调用函数出现空白
        setInterval(countDown,1000)
        function countDown(time){
             var nowTime = +new Date();
            var times = (inputTime - nowTime)/1000;
            var h = parseInt(times/60/60%24);
            h = h<10? '0'+h:h;
            hour.innerHTML = h;
            var m =parseInt(times/60%60);
            m = m<10?'0'+m:m;
            minuite.innerHTML = m;
            var s =parseInt(times%60);
            s = s<10? '0'+s:s;
            second.innerHTML = s;         
        }
       
       
    </script>
</body>
</html>